
from pyimagesearch.colordescriptor import ColorDescriptor
#from pyimagesearch.searcher import Searcher
from elasticsearch import Elasticsearch
import numpy as np
import argparse
import cv2
import json

from flask import Flask
app = Flask(__name__)

def chi2_distance(histA, histB, eps = 1e-10):
	return 0.5 * np.sum([((a - b) ** 2) / (a + b + eps) for (a, b) in zip(histA, histB)])
	
es = Elasticsearch(['192.168.1.199:9200'])

@app.route("/")
def hello():
    #return "Hello World!"

    args = {}
    args['index'] = 'index.csv'
    args['query'] = 'queries/103100.png'
    #return "Hello World!"

    # initialize the image descriptor
    cd = ColorDescriptor((8, 12, 3))

    # load the query image and describe it
    query = cv2.imread(args["query"])
    features = cd.describe(query)

    # perform the search
    searcher = Searcher(args["index"])
    results = searcher.search(features)

    return json.dumps(results);